﻿/// <reference path="../../../fly.common/fly/fly.js" />
/// <reference path="../../../fly.common/fly.mini/fly.mini-all.js" />
!function () {
    var $ = fly;
    window.indexPath = '../'
    fly.mini.ajax = $.ajax;
    //debugger
    var parent = {
        id: $.getQuery('parentId'),
        text: decodeURI($.getQuery('parentName') || '网盘'),
        iconCss: 'item-folder-root'
    }
    var fs;
    $.box.FileSelect = $.Class({
        constructor: function () {
            fs = this
            this.createMembers();
        },
        createMembers: function () {
            this.createTree()
            window.getSelection = this.getSelection;
            frameElement && (frameElement.getSelection = this.getSelection);
        },
        getSelection: function () {
            var tree = fs.tree;
            return tree.getSelectItems();
        },
        onSelectComplete: function (item, el, evt) {
            window.onSelectComplete && onSelectComplete(item);
            window.frameElement && frameElement.onSelectComplete && frameElement.onSelectComplete(item);
        },
        createTree: function () {
            this.tree = new fly.mini.Tree({
                container: document.body,
                root: parent,
                itemEvents: {
                    panel: {
                        dblclick: fs.onSelectComplete
                    }
                },
                async: {
                    url: $.box.ajaxUrl('SpaceFile', 'ForSelect', "parentId={id}&type=Folder&without="+($.getQuery('without')||'')),
                    method: "post"
                },
                // textDomFormat: '{iconDomHtml}<a name="textDom" class=f-m-item-text >{text}</a>',
                onRequestData: function (item, result) {
                    if (!result || !result.success)
                        return null;

                    for (var i = 0; i < result.data.length; i++) {
                        var n = result.data[i];
                        n.text = n.name;
                        n.iconCss = 'item-folder'
                    }
                    return result.data
                }
            });
        }
    })
} ()